package org.hagopa.games.moneypool.msgs.ContentTypes.game;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.hagopa.games.moneypool.msgs.CommandsEnum;
import org.hagopa.games.moneypool.msgs.IMsgContent;
import org.hagopa.games.moneypool.msgs.ContentTypes.UpdateTypeEnum;

public class UpdateStatus implements IMsgContent{
	
	private int marshalledSize = 0;
	private HashMap<Integer, Ustatus> updateListForPlayers = new HashMap<Integer, Ustatus>();
	
	
	public int getSize() {
		// TODO Auto-generated method stub
		return marshalledSize;
	}

	
	public byte[] marshallToByte() {
		System.out.println("Marshall Player Location");
		ByteBuffer dataArray = ByteBuffer.allocate(256);
		byte [] bytes = new byte[256];
		dataArray.putInt(CommandsEnum.UPD_PLAYER.idx());
		dataArray.putInt(UpdateTypeEnum.PLAYER_UPDATE.idx());
		
		Set<Integer> keys = updateListForPlayers.keySet();
		Iterator<Integer> itr = keys.iterator();
		int tot_sz = 0;
		while(itr.hasNext())
		{
			Integer tmp = itr.next();
			dataArray.put(updateListForPlayers.get(tmp).marshallToByte());
			tot_sz+= updateListForPlayers.get(tmp).getTotal_size();
		}
				
		dataArray.rewind();
		this.marshalledSize = tot_sz ;
		dataArray.get(bytes,0,bytes.length);
		System.out.println("return " + bytes.length + " size");
		return bytes;
		
	}

	
	public boolean unmarshallFromByte(byte[] content) {
		System.out.println("Marshall Update Status");
		
		return true;
	}

}
